package UILayer;
import java.util.ArrayList;
import CtrLayer.StaffCtr;

public class MainMenu extends InOut
{
    private StaffCtr staffCtr;  // for login
    
    public MainMenu()
    {
        staffCtr = new StaffCtr();
        login();
        mainMenu();
    }
    
    
    public void writeMenu()
    {
        String[] mainMenu = {"MAIN MENU","Orders and Leasing","Products","Discounts","Customers","Contractors","Staff","Statistics"};
        printMenu(mainMenu);
    }
    
    public void mainMenu()
    {
        boolean exit = false;
        while(!exit)
        {
            erase(1);
            writeMenu();
            int choice = inputInt("Choose: ");
            erase(1);
            switch(choice)
            {
                case 1 : {startOrders();}break;
                case 2 : {startProducts();}break;
                case 3 : {startDiscount();}break;
                case 4 : {startCustomers();}break;
                case 5 : {startContractors();}break;
                case 6 : {startStaff();}break;
                case 7 : {startStaff();}break;
                case 8 : {writeEnd();exit=true;}break;
                
                default : {};break;
            }
        }
    }
    
    public void startOrders()   { OrderUI orderUI = new OrderUI();    orderUI.start(); }
    public void startProducts() { ProductUI prodUI = new ProductUI(); prodUI.start(); }
    public void startDiscount() {DiscountUI discountUI = new DiscountUI(); discountUI.start();}
    public void startCustomers(){ CustomerUI customerUI = new CustomerUI(); customerUI.start();}
    public void startContractors() { if(!haveAccess()) {waitK();return;} ContractorUI contractorUI = new ContractorUI(); contractorUI.start();}
    public void startStaff() { if(!haveAccess()) {waitK();return;} StaffUI staffUI = new StaffUI(); staffUI.start();}
    
    public void login()
    {
        erase();
        print("########## LOGIN ########## TEST: us:1,pw:1");
        String us = inputString("Write your username: ");
        String pw = inputString("Write your password: ");
        int res = staffCtr.login(us, pw);
        if(res!=0) {logUs = us; if(res==2) access = 1;}
        else
        {
            print("Username OR Password incorrect. Try again.");
            waitK();
            login();
        }
            
    }
    
    public static void main(String[] args)
    {
    	new MainMenu();
    }
    
}
